package com.index.ylr.framework.controller;

import com.ylr.base.common.tool.Result;
import com.index.ylr.framework.rabbitmq.po.TestPo;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;


/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2022-05-26 22:32:03
 * className: TestController
 * version: 1.0
 * description:
 */
@RestController
@RequestMapping("test")
@RefreshScope
@Slf4j
public class TestController {

    @Value("${aes.secret:accc}")
    private String name;

    @GetMapping("/1")
    public Result test1() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info("调用方法了");

        return Result.success(name);
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostMapping("/2")
    public Result test2(@RequestBody TestPo testPo) {
        log.info("请求参数：{}", testPo);

        long id = IdWorker.getId();

        CorrelationData correlationData = new CorrelationData(String.valueOf(id));

        testPo.setId(id);

        rabbitTemplate.convertAndSend("retry.exchange", "retry.routing", testPo, correlationData);

        return Result.success();
    }

}
